package com.zust513.utils;

import com.zust513.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class ServletContextUtil {
    public static User getCurUser(){
        HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        User user=(User)request.getSession().getAttribute("curUser");
        return user;
    }
    public static void setCurUser(User user){
        HttpServletRequest request=((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        request.getSession().setAttribute("curUser",user);
    }

}